﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Text;

namespace Data.Mobile
{
    public class mData : IDisposable
    {
        public void Dispose()
        {
            _Layer.Dispose();
        }

        public SelectDate Date { get; set; }

        DataLayer _Layer;

        public mData(SelectDate m_Date, string ServerName, string DatabaseName, string UserName, string Password)
        {
            this.Date = m_Date;
            _Layer = new DataLayer(ServerName, DatabaseName, UserName, Password);
        }

        public bool LoginValid(string UserName, string Password, string Key)
        {
            string _pass = Util.Encrypt(Password, true);
            object _val = _Layer.Scalar("exec dbo.m_Login @UserName,@Password", "UserName,Password", UserName, _pass);

            return (Util.ToInt(_val) == 1) ? true : false;
        }

        public DataTable ProfitAndRevenue()
        {
            return _Layer.Exec("Rpt_ProfitByTime", "Command,TuNgay,DenNgay", "Summary",
                Util.ToShortDate(this.Date.FromDate), Util.ToShortDate(this.Date.ToDate));
        }

        public DataTable Qty()
        {
            return _Layer.Exec("[Rpt_QtyByTime]", "Command,TuNgay,DenNgay", "Summary",
                           Util.ToShortDate(this.Date.FromDate), Util.ToShortDate(this.Date.ToDate));
        }

        public DataTable Cost(ref bool IsDetail)
        {
            string cmd = "Detail";
            if (this.Date.FromDate.Month == this.Date.ToDate.Month)
            {
                IsDetail = true;
            }
            else
            {
                cmd = "Summary";
                IsDetail = false;
            }
            return _Layer.Exec("[Rpt_CostsByTime]", "Command,TuNgay,DenNgay", cmd,
                           Util.ToShortDate(this.Date.FromDate), Util.ToShortDate(this.Date.ToDate));
        }
    }
}
